package jiyun.com.yiyanmeng;

import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;

import java.util.ArrayList;
import java.util.List;

import adapter.YingDaoAdapter;
import base.BaseActivity;
import presenter.YingDaoPresenter;
import utils.LayoutUtil;
import utils.SpUtil;
import view.YingDaoView;

public class YingDaoActivity extends BaseActivity<YingDaoView, YingDaoPresenter> implements YingDaoView{
    private boolean isFirst;


    @Override
    public void showToast(String msg) {

    }

    @Override
    protected void initData() {

    }

    @Override
    protected void setListener() {

    }

    @Override
    protected void initView() {
        isFirst= SpUtil.get(this,"isfirst",true);
        if (isFirst){
            isFirst=false;
            SpUtil.put(this,"isfirst",isFirst);
            ViewPager vp = findViewById(R.id.yingdao_vp);
            List<View> views=new ArrayList<>();
            int[] imgs = {R.drawable.welcome_1, R.drawable.welcome_2, R.drawable.welcome_3, R.drawable.welcome_4};
            for (int i = 0; i <imgs.length ; i++) {
                View view = LayoutUtil.findLayout(this, R.layout.item_yingdao);
                ImageView img = view.findViewById(R.id.item_yingdao_img);
                img.setImageResource(imgs[i]);
                views.add(view);

            }
            YingDaoAdapter yingDaoAdapter = new YingDaoAdapter(views);
            yingDaoAdapter.setOnClickListener(new YingDaoAdapter.MyClick() {
                @Override
                public void onClick(View v) {
                    startActivity(new Intent(YingDaoActivity.this,QiDongActivity.class));
                    finish();

                }
            });
            vp.setAdapter(yingDaoAdapter);


        }else {
            startActivity(new Intent(this,QiDongActivity.class));
            finish();

        }


    }

    @Override
    protected YingDaoPresenter createPresenter() {
        return new YingDaoPresenter();
    }

    @Override
    protected int bindLayoutId() {
        return R.layout.activity_ying_dao;
    }
}
